package beans;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Paper {
	private User user;
	private Map<Question, String> answer = new HashMap<Question, String>();
	private Map<Integer, List<Question>> map;
	private List<Question> paper = new ArrayList<Question>();

	public Paper(User user, Map<Integer, List<Question>> map) {
		super();
		this.user = user;
		this.map = map;
		create();
	}

	public User getUser() {
		return user;
	}

	public Map<Question, String> getAnswer() {
		return answer;
	}

	public Map<Integer, List<Question>> getMap() {
		return map;
	}

	public List<Question> getPaper() {
		return paper;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setAnswer(Map<Question, String> answer) {
		this.answer = answer;
	}

	public void setMap(Map<Integer, List<Question>> map) {
		this.map = map;
	}

	public void setPaper(List<Question> paper) {
		this.paper = paper;
	}

	public void create() {
		for (int i = 1; i <= 10; i++) {
			int random = -1, flag = 0;
			for (int j = paper.size(); j <= i * 2;) {
				if (random != (flag = random(map.get(i).size()))) {
					random = flag;
					paper.add(map.get(i).get(random));
				}
				j = paper.size();
			}
		}
	}

	public int random(int n) {
		return (int) (Math.random() * n);
	}

}
